package com.wgchao.authmanager.domain.model;

import com.wgchao.authmanager.domain.params.HandleCreator;
import com.wgchao.authmanager.domain.params.HandleUpdator;
import lombok.Getter;

/**
 * @ClassName: Handle
 * @author: wgchao
 * @createTime: 2020/4/28 3:39 PM
 * @Description: 操作资源
 */
@Getter
public class Handle extends DomainIdentify {
    private String identify;
    private String name;
    private String remark;

    protected Handle(String identify, String name, String remark) {
        this.identify = identify;
        this.name = name;
        this.remark = remark;
    }

    public Handle(Long id, String identify, String name, String remark, Long version) {
        setId(id);
        this.identify = identify;
        this.name = name;
        this.remark = remark;
        setVersion(version);
    }

    public static Handle addHandle(HandleCreator creator){
        return new Handle(creator.getIdentify(), creator.getName(), creator.getRemark());
    }

    public void resiveInfo(HandleUpdator updator){
        if(updator.getName() != null){
            this.name = updator.getName().orElse(null);
        }
        if(updator.getRemark() != null){
            this.remark = updator.getRemark().orElse(null);
        }
    }
}
